'use strict';

const BaseController = require('../../core/base_controller');

class HelpCenterController extends BaseController {
   async index() {
    const { ctx } = this;
    const { category } = ctx.query;
    let where = {status:1}
       if(category && category!=='all'){
           where.category = category
       }
    const data = await ctx.model.HelpQuestions.findAll({
        where,
        attributes:['id','question_title','question_answer','category']
     });
    this.success(data);
   }

    async detail() {
        const { ctx } = this;
        const { id } = ctx.params
        const data = await ctx.model.HelpQuestions.findByPk(id);
        if(!data){
            ctx.throw(500,'问题不存在')
        }
        this.success(data);
    }
}

module.exports = HelpCenterController;
